package gui;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * a horizontal panel with a label and a combo box allowing the user to select a
 * an option from a series of specified strings
 * 
 * @author gke703
 */
public class ValueSelectMenu extends JPanel {

	/** combo box for user selection */
	private JComboBox selectBox;

	/**
	 * creates an displays the label/select menu
	 * 
	 * @param prompt
	 *            String, label to be displayed
	 * @param options
	 *            String array, lists the selections available to the user
	 */
	public ValueSelectMenu(String prompt, String[] options) {

		// fill in the prompt string with space to get an equal size for all
		// prompt/field combos
		while (prompt.length() < 20) {
			prompt += " ";
		}

		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		JLabel promptLabel = new JLabel(prompt);
		add(promptLabel);
		// promptLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
		add(Box.createHorizontalGlue());

		selectBox = new JComboBox(options);
		add(selectBox);
		// textField.setAlignmentX(Component.LEFT_ALIGNMENT);
		add(Box.createHorizontalGlue());
		selectBox.setMaximumSize(selectBox.getPreferredSize());

	}

	/**
	 * get selected string
	 * 
	 * @return String representation of selection
	 */
	public String getSelection() {
		return selectBox.getSelectedItem().toString();
	}

	private static final long serialVersionUID = 1L;
}